package com.gnerv.battle.boot.module.base.controller;

import com.gnerv.battle.boot.module.base.model.dto.ViewRoleDTO;
import com.gnerv.battle.boot.module.base.model.dto.ViewTreeDTO;
import com.gnerv.battle.boot.common.base.model.RestResult;
import com.gnerv.battle.boot.module.base.business.ViewBusiness;
import com.gnerv.battle.boot.module.base.model.dto.ViewCreateDTO;
import com.gnerv.battle.boot.module.base.model.dto.ViewDTO;
import com.gnerv.battle.boot.module.base.model.dto.ViewUpdateDTO;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Gnerv LiGen
 */
@RestController
@AllArgsConstructor
@RequestMapping(value = "api/manage/view")
public class ViewController {

    private final ViewBusiness viewBusiness;

    @PostMapping(value = "")
    public RestResult<Void> create(@RequestBody ViewCreateDTO viewCreateDTO) {
        return viewBusiness.create(viewCreateDTO);
    }

    @PostMapping(value = "role/bind")
    public RestResult<Void> bindRole(@RequestBody ViewRoleDTO viewRoleDTO) {
        return viewBusiness.bindRole(viewRoleDTO);
    }

    @DeleteMapping(value = "")
    public RestResult<Void> deleteByUkId(@RequestParam(value = "ukId") String ukId) {
        return viewBusiness.deleteByUkId(ukId);
    }

    @PutMapping(value = "")
    public RestResult<Void> updateByUkId(@RequestBody ViewUpdateDTO viewUpdateDTO) {
        return viewBusiness.updateByUkId(viewUpdateDTO);
    }

    @GetMapping(value = "")
    public RestResult<ViewDTO> selectByUkId(@RequestParam(value = "ukId") String ukId) {
        return viewBusiness.selectByUkId(ukId);
    }

    @GetMapping(value = "list")
    public RestResult<List<ViewDTO>> listByName(@RequestParam(required = false, name = "name") String name) {
        return viewBusiness.listByName(name);
    }

    @GetMapping(value = "tree/list")
    public RestResult<List<ViewTreeDTO>> listTree(@RequestParam(required = false, value = "parentUkId") String parentUkId) {
        return viewBusiness.listTree(parentUkId);
    }

    @GetMapping(value = "list/parent")
    public RestResult<List<ViewDTO>> listByParentUkId(@RequestParam(value = "parentUkId") String parentUkId) {
        return viewBusiness.listByParentUkId(parentUkId);
    }


}
